package com.ruicar.afs.cloud.product.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruicar.afs.cloud.common.core.query.QueryCondition;
import com.ruicar.afs.cloud.common.core.security.util.SecurityUtils;
import com.ruicar.afs.cloud.common.core.util.IResponse;
import com.ruicar.afs.cloud.product.condition.WorkTaskCondition;
import com.ruicar.afs.cloud.product.entity.WorkTaskAssign;
import com.ruicar.afs.cloud.product.service.WorkTaskAssignService;
import com.ruicar.afs.cloud.product.vo.WorkTaskLaunchVo;
import com.ruicar.afs.cloud.product.vo.WorkTaskModifyVo;
import com.ruicar.afs.cloud.product.vo.WorkTaskSumVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@AllArgsConstructor
@Api("审核任务")
@RequestMapping("/approve")
public class ApproveTaskController {

    private WorkTaskAssignService workTaskAssignService;

    @PostMapping(value = "/getWorkTaskSum")
    @ApiOperation(value = "获取待办任务汇总信息")
    public IResponse<IPage<WorkTaskSumVo>> getWorkTaskSum(@RequestBody QueryCondition<WorkTaskCondition> condition) {
        Page page = new Page(condition.getPageNumber(), condition.getPageSize());
        //获取当前用户登录名
        WorkTaskCondition workTaskCondition = condition.getCondition();
        workTaskCondition.setUsername(SecurityUtils.getUsername());
        //查询当前登录人的待办任务
        IPage<List<WorkTaskSumVo>> list = workTaskAssignService.getWorkTaskSum(page, workTaskCondition);
        return IResponse.success(list);
    }


    @PostMapping(value = "/queryApproveTaskList")
    @ApiOperation(value = "获取待办任务信息列表")
    public IResponse<IPage<WorkTaskAssign>> queryApproveTaskList(@RequestBody QueryCondition<WorkTaskCondition> condition) {
        //获取当前用户登录名
        String userName = SecurityUtils.getUsername();
        IPage<List<WorkTaskAssign>> listIPage = workTaskAssignService.page(new Page(condition.getPageNumber(), condition.getPageSize()), Wrappers.<WorkTaskAssign>query().lambda()
                .eq(WorkTaskAssign::getUserName, userName)
        );
        return IResponse.success(listIPage);
    }

    @PostMapping(value = "/queryApproveTaskLaunchList")
    @ApiOperation(value = "产品上线待办任务信息列表")
    public IResponse<IPage<WorkTaskLaunchVo>> queryApproveTaskLaunchList(@RequestBody QueryCondition<WorkTaskCondition> condition) {
        Page page = new Page(condition.getPageNumber(), condition.getPageSize());
        //获取当前用户登录名
        WorkTaskCondition workTaskCondition = condition.getCondition();
        workTaskCondition.setUsername(SecurityUtils.getUsername());
        //查询当前登录人的待办任务
        IPage<List<WorkTaskLaunchVo>> list = workTaskAssignService.queryApproveTaskLaunchList(page, workTaskCondition);
        return IResponse.success(list);
    }

    @PostMapping(value = "/queryApproveTaskModifyList")
    @ApiOperation(value = "产品修改待办任务信息列表")
    public IResponse<IPage<WorkTaskModifyVo>> queryApproveTaskModifyList(@RequestBody QueryCondition<WorkTaskCondition> condition) {
        Page page = new Page(condition.getPageNumber(), condition.getPageSize());
        //获取当前用户登录名
        WorkTaskCondition workTaskCondition = condition.getCondition();
        workTaskCondition.setUsername(SecurityUtils.getUsername());
        //查询当前登录人的待办任务
        IPage<List<WorkTaskModifyVo>> list = workTaskAssignService.queryApproveTaskModifyList(page, workTaskCondition);
        return IResponse.success(list);
    }

}
